﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace XFFSM
{

    public class FSMConditionFactory
    {

        // 创建条件
        public static void CreateCondition(RuntimeFSMController controller,FSMTransitionData transition) {

            FSMConditionData condition = new FSMConditionData();

            string parameterName = string.Empty;

            FSMParameterData parameter = null;

            if (controller.parameters.Count > 0) {
                parameter = controller.parameters[0];
                parameterName = parameter.name;
            }

            if (parameter != null)
            {
                switch (parameter.parameterType)
                {
                    case ParameterType.Float:
                        condition.compareType = CompareType.Greater;
                        break;
                    case ParameterType.Int:
                        condition.compareType = CompareType.Greater;
                        break;
                    case ParameterType.Bool:
                        condition.compareType = CompareType.Equal;
                        break;
 
                }
            }
            else {
                condition.compareType = CompareType.Greater;
            }


            condition.targetValue = 0;
            condition.parameterName = parameterName;

            transition.conditions.Add(condition);

            UnityEditor.EditorUtility.SetDirty(controller);
            UnityEditor.AssetDatabase.SaveAssets();
        }

        public static void DeleteCondition(RuntimeFSMController controller, FSMTransitionData transition,int index) {
            if ( index < 0 || index >= transition.conditions.Count ) {
                return;
            }

            transition.conditions.RemoveAt(index);


            UnityEditor.EditorUtility.SetDirty(controller);
            UnityEditor.AssetDatabase.SaveAssets();
        }

    }

}
